package com.hutao.sso.service.impl.authority;

import java.util.List;
import java.util.Map;

import javax.management.relation.RoleStatus;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.sso.dataSource.TargetDataSource;
import com.hutao.sso.mapper.newAuthority.RolesMapper;
import com.hutao.sso.pojo.newAuthority.Roles;
import com.hutao.sso.service.authority.RoleAuthorityService;
import com.hutao.sso.service.authority.RoleService;
import com.hutao.sso.util.Result;
import com.hutao.sso.util.StringUtil;

@Transactional
@Service
public class RoleServiceImpl implements RoleService{

	@Autowired
	private RolesMapper rolesMapper;
	
	@Autowired
	private RoleAuthorityService roleAuthorityService;

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public List<Map<String, Object>> findRolesListByUserHospitalId(Map<String, Object> params) {
		return rolesMapper.findRolesListByUserHospitalId(params);
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public List<Roles> findRolesListPage(Map<String, Object> params) {
		return rolesMapper.findRolesListPage(params);
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public long findRolesCountPage(Map<String, Object> params) {
		return rolesMapper.findRolesCountPage(params);
	}

	@TargetDataSource(name = "ds1")
	@Override
	public int insertRoles(Roles roles) {
		roles.setId(StringUtil.getId());
		return rolesMapper.insertRoles(roles);
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public long findCountByRoleName(Map<String, Object> params) {
		return rolesMapper.findCountByRoleName(params);
	}

	@TargetDataSource(name = "ds1")
	@Override
	public int updateRoles(Roles roles) {
		return rolesMapper.updateRoles(roles);
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public Roles findRoleById(Map<String, Object> params) {
		return rolesMapper.findRoleById(params);
	}

	@TargetDataSource(name = "ds1")
	@Override
	public Result deleteRoleById(Map<String, Object> params) {
		roleAuthorityService.deleteRoleAuthorityByRoleId(params);
		rolesMapper.deleteRoleById(params);
		return new Result(true, "删除成功!");
	}

	/**
	 * 通过userHospitalId查询所有的角色
	 * 
	 */
	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public List<Map<String, Object>> findRoleListByUserHospitalId(Map<String, Object> params) {
		return rolesMapper.findRoleListByUserHospitalId(params);
	}
	
	
	
	

}



